package com.wy2.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wy2.entity.Student;
import com.wy2.service.zxStuService;
import com.wy2.util.FenyeUtil;

@RequestMapping("/stus")
@RestController
public class zxStuController {
	@Autowired
	private zxStuService zxs;
	
	/**
	 * 分页工具类
	 * @param fenye
	 * @param student
	 * @return
	 */
	@GetMapping
	public FenyeUtil<Student> getAll( FenyeUtil<Student> fenye,Student student){
		//把查询所有的参数传到分页工具类
		fenye.setT(student);
		fenye = zxs.getAll(fenye);
		return fenye;
	}	
	/**
	 * 添加
	 * @param s
	 * @return
	 */
	@RequestMapping("/addstudent")
	public Integer addMod(Student s) {
		return zxs.addStudent(s);
	}
	/**
	 * 修改
	 * @param s
	 * @return
	 */
	@RequestMapping("/updstudent")
	public Integer updMod(Student s) {
		return zxs.updStudent(s);
	}
	/**
	 * 删除
	 * @param sid
	 * @return
	 */
	@RequestMapping("/delstudent")
	public Integer delMod(Integer sid) {
		System.out.println("---id"+sid);
		return zxs.delStudent(sid);
	}
	/**
	 * 修改
	 * @param sid
	 * @return
	 */
	@RequestMapping("/updateExt")
	public Integer updateExt(Integer sid) {
		System.out.println(sid+"-------");
		return zxs.updateExt(sid);
	}
	/**
	 * 查询学生
	 * @param fenye
	 * @param student
	 * @return
	 */
	@RequestMapping("/findByExt")
	public FenyeUtil<Student> findByExt(FenyeUtil<Student> fenye,Student student){
		fenye.setT(student);
		return zxs.findByExt(fenye);
	}
	
	//查重复
	//手机号唯一
	@RequestMapping("/cstel")
	public Integer Stel(String stel) {
		List<Student> list = zxs.Stel(stel);
		if(list != null && list.size()  >0) {
			return 1;
		}else {
			return 0;
		}
		
		
	}
	//qq号唯一
	@RequestMapping("/csqq")
	public Integer Sqq(String sqq) {
		List<Student> list = zxs.Sqq(sqq);
		if(list != null && list.size()  >0) {
			return 1;
		}else {
			return 0;
		}
		
		
	}
	//微信唯一
	@RequestMapping("/cschart")
	public Integer Schart(String schart) {
		List<Student> list = zxs.Schart(schart);
		if(list != null && list.size()  >0) {
			return 1;
		}else {
			return 0;
		}
		
		
	}
	
}
